const db = require('../config/DB')

class UsersModel {
  //验证用户
  checkUser(username, password) {
    return db.query("SELECT * FROM users WHERE username=? AND `password`=? AND `status`=1; ", [username, password])
  }

  //根据账号查找用户
  findUserByUserName(username) {
    return db.query('SELECT * FROM users WHERE username=? AND status=1; ', [username])
  }

  //根据昵称查找用户
  findUserByNicName(nic_name) {
    return db.query('SELECT * FROM users WHERE nic_name like ? AND status=1; ', [nic_name])
  }

  //添加用户
  createUser(body) {
    return db.query("INSERT INTO users SET?; ", [body])
  }

  //修改用户
  updateUserById(body, id) {
    return db.query("UPDATE users SET ? WHERE id=?; ", [body, id])
  }
}

module.exports = new UsersModel();
